package com.tt.mymu.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tt.mymu.entity.Sub;
import com.tt.mymu.mapper.SubMapper;
import com.tt.mymu.service.SubService;
import com.tt.mymu.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubServiceImpl implements SubService {

    @Autowired
    private SubMapper subMapper;


    @Override
    public Result getSubListById(Integer menuId) {

        QueryWrapper<Sub> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", menuId);
        List<Sub> subs = subMapper.selectList(queryWrapper);
        return Result.success(subs);
    }

    @Override
    public Result getSubList() {
        List<Sub> subs = subMapper.selectList(null);
        return Result.success(subs);
    }

    @Override
    public Result addSub(Sub sub) {
        int insert = subMapper.insert(sub);
        return Result.success(insert);
    }

    @Override
    public Result updateSub(Sub sub) {
        int i = subMapper.updateById(sub);
        return Result.success(i);
    }

    @Override
    public Result deleteSub(Integer id) {
        int i = subMapper.deleteById(id);
        return Result.success(i);
    }
}
